using System;

namespace BanckUtil {
    
class ATM {
    private Bank bank;

    public ATM(Bank bank) {
        this.bank = bank;
    }

    public void GetInput() {
        string input = Console.ReadLine();
        int i = Int32.Parse(input);

        int money;
        string id, pwd;

        switch (i)
        {
            case 1:
                Console.WriteLine(">>>>Create Account<<<<");

                Console.WriteLine("Input your ID:");
                id = Console.ReadLine();
                Console.WriteLine("Input your PWD:");
                pwd = Console.ReadLine();
                Console.WriteLine(bank.OpenAccount(id, pwd) ? "CREATE SUCCESS !" : "CREATE FAILED!");
                break;

            case 2:
                Console.WriteLine(">>>>Delete Account<<<<");

                Console.WriteLine("Input your ID:");
                id = Console.ReadLine();
                Console.WriteLine("Input your PWD:");
                pwd = Console.ReadLine();
                Console.WriteLine(bank.CloseAccount(id, pwd) ? "DELETE SUCCESS !" : "DELETE FAILED!");

                break;
            case 3:
                Console.WriteLine(">>>>Show Accont Info<<<<");

                Console.WriteLine("Input your ID:");
                id = Console.ReadLine();

                if (bank.FindAccount(id) != null) {
                    Console.WriteLine("Account find! Input your password");
                    pwd = Console.ReadLine();
                    if (bank.FindAccount(id).IsMatch(pwd)) {
                        Console.WriteLine(bank.FindAccount(id));
                    } else {
                        Console.WriteLine("PWD ERROR");
                    }
                } else {
                    Console.WriteLine("Account not found");
                    break;
                }

                break;
            case 4:
                Console.WriteLine(">>>>Save Money<<<<");
                Console.WriteLine("Input your ID:");
                id = Console.ReadLine();

                if (bank.FindAccount(id) != null) {
                    Console.WriteLine("Account find! Input your password");
                    pwd = Console.ReadLine();
                    if (bank.FindAccount(id).IsMatch(pwd)) {
                        Console.WriteLine("AUTH SUCCESS! Please input a num");
                        money = Int32.Parse(Console.ReadLine());
                        bank.FindAccount(id).SaveMoney(money);
                    } else {
                        Console.WriteLine("PWD ERROR");
                    }
                } else {
                    Console.WriteLine("Account not found");
                    break;
                }
                break;
            case 5:
                Console.WriteLine(">>>>Withdraw Money<<<<");
                Console.WriteLine("Input your ID:");
                id = Console.ReadLine();

                if (bank.FindAccount(id) != null) {
                    Console.WriteLine("Account find! Input your password");
                    pwd = Console.ReadLine();
                    if (bank.FindAccount(id).IsMatch(pwd)) {
                        Console.WriteLine("AUTH SUCCESS! Please input a num");
                        money = Int32.Parse(Console.ReadLine());
                        bank.FindAccount(id).WithDraw(money);
                    } else {
                        Console.WriteLine("PWD ERROR");
                    }
                } else {
                    Console.WriteLine("Account not found");
                    break;
                }
                break;
            default:
                break;
        }
    }

    public void Show() {
        Console.WriteLine("1. Create Account");
        Console.WriteLine("2. Delete Account");
        Console.WriteLine("3. Show Accont Info");
        Console.WriteLine("4. Save Money");
        Console.WriteLine("5. Withdraw Money");
    }

    public void Transaction() {

    }
}

}
